package com.shgsh.attribute.service;

import com.lovver.ssdbj.pool.SSDBPoolConnection;
import com.shgsh.attribute.repository.TestRepository;
import com.shgsh.common.model.User;
import com.shgsh.common.repository.BasicRepository;
import com.shgsh.common.repository.CURDRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * Created by jessy on 2015/8/4.
 */
@Service("testService")
public class TestService {

    Logger logger = LoggerFactory.getLogger(TestService.class);


    @Autowired
    BasicRepository basicRepository;
    @Autowired
    TestRepository testRepository;
    @Autowired
    CURDRepository curdrepository;

    SSDBPoolConnection conn = null;

    public void connect(){
        conn = basicRepository.init();
    }

    public void addUser(){

//            connect();
            ArrayList paramsset = new ArrayList();
            paramsset.add("user_base_detail".getBytes());
            paramsset.add("20000".getBytes());
            User user = new User();
            user.setId("20000");
            user.setPassword("111");
            user.setAddress("address");
            user.setConfirm(1);
            user.setGener(0);
            user.setName("haha");
            user.setNick_name("h");
            user.setPhone("687592");
            user.setHobby("ee");
            paramsset.add(user.toJson().getBytes());
        curdrepository.mset(paramsset);
        curdrepository.del("b");
        /*scanAll*/
        System.out.println("********************************scanAll****************************************");
        curdrepository.scanAll();
        System.out.println("*******************************rscanAll****************************************");
        curdrepository.rscanAll();
        System.out.println("*******************************hscanAll****************************************");
        curdrepository.hscanAll("");
        System.out.println("*******************************hset****************************************");
        curdrepository.hset(paramsset);
        System.out.println("*******************************hget****************************************");
        ArrayList paramgset = new ArrayList();
        paramgset.add("user_base_detail".getBytes());
        paramgset.add("20000".getBytes());
        curdrepository.hget(paramgset);
        System.out.println("*******************************zget****************************************");
        System.out.println("*****************************zset****************************************");
        System.out.println("*******************************zdel****************************************");
        System.out.println("*******************************multi_del****************************************");
        System.out.println("*******************************multi_hdel****************************************");
        System.out.println("*******************************hkeysall****************************************");
        System.out.println("*******************************hdel****************************************");
        ArrayList paramdel = new ArrayList();
        paramdel.add("user_base_detail".getBytes());
        paramdel.add("20000".getBytes());
        curdrepository.hdel(paramdel);
    }

    public void test(){
        try {
            connect();

            ArrayList mset_params = new ArrayList();
            mset_params.add("key1".getBytes());
            mset_params.add("hahahahaha".getBytes());
            mset_params.add("key2".getBytes());
            mset_params.add("lalalalala".getBytes());
            conn.executeUpdate("multi_set", mset_params);







        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}
